package com.jmb.api.common.exception;

import com.jmb.api.common.result.ResultCodeEnum;
import lombok.Data;

@Data
public class WebApiException extends RuntimeException{
    // 异常状态码
    private Integer code;
    /**
     * 通过状态码和错误消息创建异常对象
     * @param message
     * @param code
     */
    public WebApiException(String message, Integer code) {
        super(message);
        this.code = code;
    }
    public WebApiException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }
    @Override
    public String toString() {
        return "ApiException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
